//
//  DYAddContentViewController.m
//  DaYing
//
//  Created by DaYing on 2023/12/31.
//  Copyright © 2023 DaYing. All rights reserved.
//

#import "DYAddContentViewController.h"

#import "DYAddContentTextCell.h"
#import "DYGroupSettingsTitleCell.h"
#import "DYGroupingResultsTitleCell.h"
#import "DYLotteryDecisionButtonCell.h"

@interface DYAddContentViewController ()

@end

@implementation DYAddContentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationBar.backgroundColor = [UIColor clearColor];
    [self setNavigationItemTitleViewWithTitle:@"分组内容"];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"DYAddContentTextCell" bundle:nil] forCellReuseIdentifier:@"DYAddContentTextCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"DYGroupSettingsTitleCell" bundle:nil] forCellReuseIdentifier:@"DYGroupSettingsTitleCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"DYGroupingResultsTitleCell" bundle:nil] forCellReuseIdentifier:@"DYGroupingResultsTitleCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"DYLotteryDecisionButtonCell" bundle:nil] forCellReuseIdentifier:@"DYLotteryDecisionButtonCell"];
    
    self.tableView.frame = CGRectMake(0,self.navigationBarHeight, kScreenWidth, kScreenHeight - self.navigationBarHeight);
}

#pragma mark - cellDataSource

- (NSArray *)cellDataSource {
    
    if (!self.dataSource) {
        NSMutableArray *arr = [NSMutableArray arrayWithCapacity:4];
        
        __block NSMutableArray *subarr = nil;
        __block NSDictionary *dict = nil;
                
        subarr = [NSMutableArray arrayWithCapacity:1];
        
        dict =  @{@"class":DYGroupSettingsTitleCell.class,
                  @"height":@([DYGroupSettingsTitleCell getCellFrame:[NSNumber numberWithFloat:60]]),
                  @"data":[DYGroupSettingsTitleCellModel ittemModelWithTitle:@""],
                  @"delegate":@YES};
        [subarr addObject:dict];
        
        dict =  @{@"class":DYAddContentTextCell.class,
                  @"height":@([DYAddContentTextCell getCellFrame:[NSNumber numberWithFloat:290]]),
                  @"data":[DYAddContentTextCellModel ittemModelWithTitle:@"" content:_content tip:@"请输入内容，每行一个" max:@"500"],
                  @"delegate":@YES};
        [subarr addObject:dict];
        
        dict =  @{@"class":DYGroupingResultsTitleCell.class,
                  @"height":@([DYGroupingResultsTitleCell getCellFrame:[NSNumber numberWithFloat:170]]),
                  @"data":[DYGroupingResultsTitleCellModel ittemModelWithTitle:@""]};
        [subarr addObject:dict];

        dict =  @{@"class":DYLotteryDecisionButtonCell.class,
                  @"height":@([DYLotteryDecisionButtonCell getCellFrame:[NSNumber numberWithFloat:62]]),
                  @"data":[DYLotteryDecisionButtonCellModel ittemModelWithTitle:@"保存"],
                  @"delegate":@YES};
        [subarr addObject:dict];
   
        [arr addObject:subarr];

        self.dataSource = arr;
    }
    return self.dataSource;
}

#pragma mark DYGroupSettingsTitleCellDelegate 清空

- (void)groupSettingsTitleCell:(DYGroupSettingsTitleCell *)cell button:(UIButton *)sender; {
    _content = @"";
    [self refreshData];
}

#pragma mark DYAddContentTextCellDelegate 拓展名输入

- (void)addContentTextCell:(DYAddContentTextCell *)cell textView:(UITextView *)textView {
    _content = textView.text;
}

#pragma mark DYLotteryDecisionButtonCellDelegate 保存

- (void)lotteryDecisionButtonCell:(DYLotteryDecisionButtonCell *)cell button:(UIButton *)sender {
    if (_completion) {
        _completion(self,_content);
    }
    [self backAction:nil];
}

@end
